clc
clear

T =1;
t = linspace(0,pi,1000);
x=1/2*square(2*pi*t/T);
figure (1)
plot(t,x,'r')
grid on 
hold on

k=1:2:41;
fourier_x=0;

for i =1:1:20
    fourier_x=fourier_x+2/(k(i)*pi)*sin(2*pi*k(i)*t/T);
end

plot(t,fourier_x,'b')